package gmed;
import java.sql.*;

public class DBConnection {


	
	public static void main(String args[]){
		
		Connection conn;
		String url ="jdbc:mysql://192.168.2.101:3306/";
		String dbName ="tp1sd";
		String driver = "com.mysql.jdbc.Driver";
		String userName = "luciana";
		String password = "123456";
		
		conn =null;
		try{
			Class.forName(driver).newInstance();
			conn = DriverManager.getConnection(url+dbName,userName,password);
			
			Statement st=conn.createStatement();
			
			boolean r=st.execute("insert into medico (nlicenca,nome,idesp) values (50,'Pedro','2')",st.RETURN_GENERATED_KEYS);
			//boolean r=st.execute("select idMedico,nlicenca,nome,especialidade from Medico where nlicenca=49",st.RETURN_GENERATED_KEYS);
			
			System.out.println("Resultado: "+r);
			ResultSet rs=st.getGeneratedKeys();
			if (rs.first()){ 
			System.out.println("insert com ID "+rs.getInt(1));
			}
			}catch (Exception e){
			e.printStackTrace();
		}
	}
	
}
